package com.jett.mycloud.controller;

import com.jett.mycloud.entities.Pay;
import com.jett.mycloud.entities.PayDTO;
import com.jett.mycloud.resp.ResultData;
import com.jett.mycloud.service.PayService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author : 王雪峰
 * @description: TODO
 * @date : 2024/2/29 17:02
 */
@RestController
@Slf4j
@Tag(name="支付微服务模块",description = "支付CRUD")
public class PayController {
    @Resource
    PayService payService;
    @PostMapping(value = "/pay/add")
    @Operation(summary = "新增",description = "新增支付流水方法,json串做参数")
    public ResultData<String> addPay(@RequestBody Pay pay){
        int add=payService.add(pay);
        return  ResultData.success("成功插入记录");
    }
    @DeleteMapping(value = "/pay/delete/{id}")
    @Operation(summary = "删除",description = "通过id删除支付流水方法")
    public ResultData<Integer> deletePay(@PathVariable("id") int id){
        int delete = payService.delete(id);
        return ResultData.success(delete);
    }
    @PutMapping(value = "/pay/update")
    @Operation(summary = "更新",description = "更新支付流水方法")
    public ResultData<Integer> updatePay(@RequestBody PayDTO payDTO){
        Pay pay = new Pay();
        BeanUtils.copyProperties(payDTO,pay);
        int update = payService.update(pay);
        return ResultData.success(update);
    }
    @GetMapping(value = "/pay/get/{id}")
    @Operation(summary = "通过id查询",description = "通过id查询支付流水方法")
    public ResultData<Pay> getById(@PathVariable("id") int id){
        Pay payInfo = payService.getById(id);
        return ResultData.success(payInfo);
    }
    @GetMapping(value = "/pay/getAll")
    @Operation(summary = "查询全部",description = "查询全部支付流水方法")
    public ResultData<List<Pay>> getAll(){
        List<Pay> payInfoAll = payService.getAll();
        return ResultData.success(payInfoAll);
    }


}
